package org.space.galaxyCabinet.controller;

import org.space.galaxyCabinet.domain.Device;
import org.space.galaxyCabinet.domain.DeviceStatus;
import org.space.galaxyCabinet.service.DeviceService;
import org.space.galaxyCabinet.service.InfluxDBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

@RestController
@RequestMapping("/cabinetControl")
@CrossOrigin(origins = "*") // 允许来自
public class CabinetControlController {
    @Autowired
    private DeviceService deviceService;

    @Autowired
    private InfluxDBService influxDBService;

    @PostMapping("/status")
    public boolean updateStatus(Device device) {
        return deviceService.updateStatus(device);
    }

    @PostMapping("/get/status")
    public List<DeviceStatus> getStatus(String deviceNo, String start, String end) {
        return influxDBService.queryDeviceStatusByConditions(deviceNo, start, end);
    }
    @GetMapping("/get/status")
    public List<DeviceStatus> queryByDateTime(
        @RequestParam String deviceNo
    ) {
        // 执行查询...
        return influxDBService.queryDeviceStatusByConditions(deviceNo);
    }
}
